<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'updateadvertisment.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  <script>
  		function updateImg(){
  				  var count = $('input:checked').length;
  				  if(count==0){
  				  		alert("您未选择任何项");
  				  }else{
  				  		if(count>5){
  				  			alert("最多只能选5项");
  				  		}else{
  				  			var str='';
  							$('input[name="check"]:checked').each(function(){
  							    var address = $(this).parent().parent().find('textarea').val()
    							str+=$(this).val()+'---'+address+',';
  							}); 
  							$.post("UpdateAdvertismentImageAction",{"checkId":str},function(data){
  								if(data=="success"){
  									alert("设置成功");
  									 location.replace(location.href);
  								}
  							});
  				  		}
  				  }
  				  
  		}
  		function deleteAdvImg(id,imageName){
  		     if(confirm("是否删除")){
  				$.post("DeleteAdvertismentImageAction",{"imageId":id,"imageName":imageName},function(data){
  					if(data=="success"){
  							alert("删除成功");
  							location.reload();
  					}else{
  						alert("删除失败");
  					}
  				});
  			}
  		}
  		function updateAdvImgaddress(address){
  			alert(address);
  		}
  </script>
  </head>
  
  <body>
    		<div align="left">
    				<div style="width: 600px;">
    					<c:if test="${fn:length(adv)<=0}">
    							暂时没有任何的广告图片
    					</c:if>
    					<c:if test="${fn:length(adv)>0}">
    						<table border="1">
    								<tr align="center">
    										<td>图片</td>
    										<td>图片链接地址</td>
    										<td width="">是否作为显示</td>
    										<td>是否删除</td>
    								</tr>
    								<c:forEach items="${adv}" var="advertisment">
	    								<tr align="center">
	    										
	    										<td><img width="200px;" height="100px;" src="${advertisment.imageName}"></td>
	    										<td><textarea style="width:466px;height:108px;">${advertisment.imageAddress}</textarea></td>
	    										<td>
	    										
	    												<c:if test="${advertisment.isShow==0}">
	    													<input type="checkbox" name="check" value="${advertisment.imageId}" style="width:50px;">
	    												</c:if>
	    												<c:if test="${advertisment.isShow==1}">
	    													<input type="checkbox" name="check" value="${advertisment.imageId}" checked="checked" style="width:50px;">
	    												</c:if>
	    										
	    										</td> 
	    										<td><div style="width:45px;">
	    										<a style="cursor:pointer;" onclick="deleteAdvImg(${advertisment.imageId},'${advertisment.imageName}')">删除</a>
	    										</div></td>
	    								</tr>
    								</c:forEach>
    								<tr>
    										<td colspan="4" align="center">
    											<input type="button" value="提交" onclick="updateImg()">
    										</td>
    								</tr>
    						</table>
    					</c:if>
    				</div>
    		</div>
  </body>
</html>
